package org.orz.story.member.biz.account.web.admin;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.orz.cloud.auth.ServiceContextUtil;
import org.orz.cloud.auth.domain.UserInfo;
import org.orz.cloud.common.result.ResultDTO;
import org.orz.cloud.common.result.ResultPageDTO;
import org.orz.story.member.biz.account.model.req.*;
import org.orz.story.member.biz.account.model.resp.ListAccountInfoResp;
import org.orz.story.member.biz.account.service.MemAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "管理端账户相关接口")
@RestController
@RequestMapping("/admin/account")
public class AdminAccountController {
    @Autowired
    private MemAccountService memAccountService;

    /**
     * TODO 暂时没用到
     */
    @ApiOperation("注册")
    @PostMapping("register")
    public ResultDTO register(@RequestBody RegisterReq dto){
        memAccountService.register(dto);
        return ResultDTO.success();
    }

    @PostMapping("login")
    @ApiOperation("管理端登录")
    public ResultDTO<UserInfo> adminLogin(@RequestBody LoginReq dto){
        return ResultDTO.success(memAccountService.login(dto, ServiceContextUtil.getWorkbenchWithExistCheck()));
    }

    @ApiOperation("分页查询账户列表")
    @PostMapping("listAccountInfo")
    public ResultPageDTO<ListAccountInfoResp> listAccountInfo(@RequestBody ListAccountInfoReq req){
        return ResultPageDTO.restPage(memAccountService.listAccountInfo(req), ListAccountInfoResp.class);
    }

    @ApiOperation("添加账号")
    @PostMapping("addAccount")
    public ResultDTO<Boolean> addAccount(@RequestBody AddAccountReq req){
        memAccountService.addAccount(req);
        return ResultDTO.success();
    }

    @ApiOperation("更新账户信息")
    @PostMapping("updateAccount")
    public ResultDTO<Boolean> updateAccount(@RequestBody UpdateAccountReq req){
        memAccountService.updateAccount(req);
        return ResultDTO.success();
    }

}
